import {
  Style,
  createAPI,
  Toast
} from 'cube-ui';
import Vue from 'vue'
import loading from "cpnts/loading";
import {getHashString, versions} from './utl'
import eventBus from 'common/js/aggregation'
// import aggregation from "./aggregation";

Vue.use(Toast)

createAPI(Vue, loading, [], true)



Vue.prototype.$loading = function(info='数据加载中..'){
  this.$createLoading({
    content: info
  }).show()
}

Vue.prototype.$loadingHide = function(){
  this.$createLoading({}).hide()
}

Vue.prototype.$eventBus = eventBus

Vue.prototype.$warn = function(info){
  this.$createToast({
    time: 2500,
    type: 'warn',
    txt: info
  }).show()
}

Vue.prototype.$suc = function(info){
  this.$createToast({
    time: 2500,
    type: 'correct',
    txt: info
  }).show()
}


let token = getHashString('token') || localStorage.getItem('app_token') || '';
let uid = getHashString('uid');
let phone = getHashString('phone');
let area = getHashString('area');
let shopToken = getHashString('shopToken');

if(token){
  localStorage.setItem('app_token', token)
}
window['appToken'] = token;
window['uid'] = uid;
window['phone'] = phone;
window['area'] = area;
window['shopToken'] = shopToken;


if(versions.ios && versions.getIosVer() > 10){
  // 阻止双击放大
  let lastTouchEnd = 0;
  document.addEventListener('touchstart', function(event) {
    if (event.touches.length > 1) {
      event.preventDefault();
    }
  });
  document.addEventListener('touchend', function(event) {
    var now = (new Date()).getTime();
    if (now - lastTouchEnd <= 300) {
      event.preventDefault();
    }
    lastTouchEnd = now;
  }, false);


// 阻止双指放大
  document.addEventListener('gesturestart', function(event) {
    event.preventDefault();
  });
}



//
// if(versions.android){
//   let timeout
//   window.addEventListener("resize", function() {
//     if(document.activeElement.hasAttribute('viewneeded')) {
//       window.setTimeout(function() {
//         document.activeElement.scrollIntoViewIfNeeded();
//       },0);
//       //alert(22)
//       // clearTimeout(timeout)
//       // timeout = null
//     }
//   })
//
// }


